<template>
	<view class="page"
		:style="{ background: `url(${backimg}) no-repeat` }">
		<view class="flex benben-position-layout flex flex-wrap align-center registers_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub registers_fd0_0'>
				<view class='flex align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
				</view>
				<view class='flex flex-wrap align-stretch justify-center flex-sub'>
				</view>
				<view class='flex flex-wrap align-center registers_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<!---flex布局flex布局开始-->
		<view class="flex benben-flex-layout flex-wrap align-center">
			<view class='flex flex-direction flex-wrap align-center flex-sub registers_fd1_0'>
				<image class='registers_fd1_0_c0' mode="aspectFill" :src='STATIC_URL+"logo1.jpg"'></image>
			</view>
		</view>

		<!---flex布局flex布局结束-->
		<!---登录flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout registers_flex_2">
			<view class='flex flex-wrap align-center registers_fd2_0' @tap.stop="pickerDiy1678760201193=true">
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"78.png"'></image>
				<input class='flex-sub registers_fd2_0_c1' type="text" placeholder="请选择区号" confirm-type="done" style="pointer-events:none;"
					:maxlength="-1" disabled="true" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
					v-model="area" />
			</view>
			<view class='flex flex-wrap align-center registers_fd2_0'>
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"56.png"'></image>
				<input class='flex-sub registers_fd2_0_c1' type="number" placeholder="请输入手机号" confirm-type="done" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" maxlength="20" v-model="mobile" />
			</view>
			<view class='flex flex-wrap align-center registers_fd2_0'>
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"57.png"'></image>
				<input class='flex-sub registers_fd2_1_c1' type="number" placeholder="请输入验证码" confirm-type="done"
					:maxlength="6" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="code" />
				<benben-send-verification-code class='flex  registers_fd2_1_c2' after-text='后重新获取' before-text='获取验证码'
					:type='type' :phone="mobile" :area_code='list'></benben-send-verification-code>
			</view>
			<view class='flex flex-wrap align-center registers_fd2_0'>
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"58.png"'></image>
				<benben-flex-password-diy v-model="password"
					class-name="flex align-center flex-sub flex registers_fd2_2_c1" :placeholder="'请输入密码(6~12位字母+数字)'"
					:maxlength="12" :default-type='true'
					placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx">
					<template #show>
						<text class='fu-iconfont2  registers_fd2_2_c1_icon1' data-type="show">&#xE837;</text>
					</template>
					<template #hide>
						<text class='fu-iconfont2  registers_fd2_2_c1_icon2' data-type="hide">&#xEBCC;</text>
					</template>
				</benben-flex-password-diy>
			</view>
			
			<view class='flex flex-wrap align-center registers_fd2_0' v-if="sex == 2">
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"12.png"'></image>
				<input class='flex-sub registers_fd2_0_c1' type="text" placeholder="请输入邮箱号码" confirm-type="done"
					:maxlength="15" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="email" />
			</view>
			<view class='flex flex-wrap align-center registers_fd2_0' v-if="sex == 2">
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"13.png"'></image>
				<input class='flex-sub registers_fd2_0_c1' type="text" placeholder="请输入微信号" confirm-type="done"
					:maxlength="15" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="wx" />
			</view>
			<view class='flex flex-wrap align-center registers_fd2_0'>
				<image class='registers_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
				<input class='flex-sub registers_fd2_0_c1' type="text" placeholder="请输入邀请码(选填)" confirm-type="done"
					:maxlength="15" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="invite"
					@input="handleInput" />
			</view>
			<view class='flex flex-direction align-stretch justify-center registers_fd2_4'>
				<button class='registers_fd2_4_c0' @tap.stop="registerConfirmFunc()">注册</button>
			</view>
			<view class='flex flex-wrap align-center justify-center registers_fd2_5'>
				<text class='registers_fd2_5_c0'>已有账号，前去</text>
				<text class='registers_fd2_5_c1' @tap.stop="godenglu">登录</text>
			</view>
		</view>

		<!---登录flex布局结束-->
		<view class="flex flex-wrap align-center justify-center  flex registers_flex_3">
			<benben-flex-switch-new class-name='flex flex' v-model="kaiguan" :disabled='false'>
				<template v-slot:checked>

					<view class='flex flex position-relative align-center registers_checkfd3_0_c0'>
						<image class='registers_checkfd3_0_c0_c0' mode="aspectFill" :src='STATIC_URL+"1.png"'></image>
					</view>

				</template>
				<template v-slot:unchecked>

					<view class='flex flex position-relative justify-end align-center registers_checkfd3_0_c0'>
						<image class='registers_noCheckfd3_0_c1_c0' mode="aspectFill" :src='STATIC_URL+"51.png"'></image>
					</view>

				</template>
			</benben-flex-switch-new>
			<text class='registers_fd3_1'>已阅读并同意</text>
			<text class='registers_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dlzc/conceal/conceal?type=1`">《用户注册协议》</text>
			<text class='registers_fd3_3'>与</text>
			<text class='registers_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dlzc/conceal/conceal?type=2`">《隐私政策》</text>

		</view>
		<!--区号选择器开始 -->
		<benben-picker ref="benbenWritePickerCodepicker11" :visible.sync="pickerDiy1678760201193" :label.sync='area'
			:value.sync='list' :options='areaList' mode='selector' :mask-show='true' :timeout='true' :picker-height='88'
			default-type='prefix' :default-props='{"label":"country","value":"prefix"}'>
			<template #picker-header>
				<view class='flex flex-wrap align-center justify-between MyInformation_picker5_0'>
					<text @tap="$refs.benbenWritePickerCodepicker11.cancel()">取消</text>
					<text>区号</text>
					<text class='MyInformation_picker5_0_c2'
						@tap="$refs.benbenWritePickerCodepicker11.pickerConfirm()">确认</text>
				</view>
			</template>
		</benben-picker>


	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	import {getImLogin, loginTUICallKit} from '@/commen/login.js'
	export default {
		components: {},
		data() {
			return {
				"mobile": "",
				"code": "",
				"password": "",
				"kaiguan": false,
				"invite": "",
				area: '',
				"pickerDiy1678760201193": false,
				list: '',
				areaList: [],
				type: 7,
				sex: '',
				email: '',
				wx: '',
				uesrlist: {},
				backimg: '',
				timerId: null
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let a = uni.getStorageSync('backgound')
			this.backimg = a
			this.getarea()
			this.sex = options.sex
			this.email = options.email
			this.wx = options.wx
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//获取背景图
			// async getimg() {
			//   let res = await this.$api.post(global.apiUrls.a647dc0f8b7df1);
			//   console.log(res, 'ressssssss')
			//   if (res.data.code != 1) {
			//     this.$message.info(res.data.msg)
			//     return
			//   }
			//   this.backimg = res.data.data.app_bg_img
			//   console.log(this.backimg, 'this.backimg')
			// },
			//去登录
			godenglu() {
				uni.navigateTo({
					url: '/pages/tabBar/login/login'
				})
			},
			//限制邀请码
			handleInput(event) {
				const newValue = event.target.value.replace(/[^\da-zA-Z]/g, ""); // 只保留数字和大小写字母字符
				if (newValue !== event.target.value) {
					event.target.value = newValue; // 更新输入框的值
					this.invite = newValue; // 更新组件实例中的数据
				}
			},
			// 获取区号
			async getarea() {
				let res = await this.$api.post(global.apiUrls.arealist);
				if (res.data.code != 1) {
					this.$message.info(res.data.msg)
					return
				}
				this.areaList = res.data.data
				console.log(this.areaList, 'this.areaList')
			},
			//注册
			async registerConfirmFunc() {
				if (this.timerId) {
					clearTimeout(this.timerId)
				}
				if (!validate(this.list, 'require')) {
					this.$message.info('请选择区号');
					return false;
				}
				if (!validate(this.mobile, 'require')) {
					this.$message.info('请输入手机号');
					return false;
				}
				
				// if (!validate(this.mobile, 'phone')) {
				// 	this.$message.info('请输入正确的手机号');
				// 	return false;
				// }
				if (!validate(this.code, 'require')) {
					this.$message.info('请输入验证码');
					return false;
				}
				if (!validate(this.code, 'captcha')) {
					this.$message.info('请输入正确的验证码');
					return false;
				}
				if (!validate(this.password, 'require')) {
					this.$message.info('请输入密码');
					return false;
				}
				if (!validate(this.password, 'password')) {
					this.$message.info('请输入正确的密码');
					return false;
				}
				if (this.sex == 2) {
					if (!validate(this.email, 'require')) {
						this.$message.info('请输入邮箱号码');
						return false;
					}
					if (!validate(this.email, 'email')) {
						this.$message.info('请输入正确的邮箱号码');
						return false;
					}
					if (!validate(this.wx, 'require')) {
						this.$message.info('请输入微信号');
						return false;
					}
				}
				if (this.kaiguan === false) {
					this.$message.info('请阅读并同意用户注册协议和隐私政策');
					return false;
				}
				this.timerId = setTimeout(async () => {
					let res = await this.$api.post(global.apiUrls.register, {
						mobile: this.mobile,
						code: this.code,
						type: this.type,
						password: this.password,
						invite_code: this.invite,
						sex: this.sex,
						area_code: this.list,
						email: this.email,
						wx: this.wx
					});
					if (res.data.code != 1) {
						this.$message.info(res.data.msg);
						return
					}
					this.$message.info(res.data.msg);
					this.timerId = null;
					this.$store.commit('updateUserInfo', res.data.data.userinfo);
					this.$store.commit('saveToken', res.data.data.userinfo.user_token);
					let options = {
						t_user_id: res.data.data.userinfo.t_user_id,
						user_sig: res.data.data.userinfo.user_sig,
					}
					getImLogin(options);
					// #ifdef APP-PLUS
					loginTUICallKit(options);
					// #endif
					setTimeout(() => {
						// this.$urouter.navigateTo(`/pages/tabBar/login/login`);
						uni.reLaunch({
							url: '/pages/tabBar/index/index'
						})
					}, 800)
				}, 200)
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		height: calc(100vh - var(--window-bottom));
		background-size: 100% 100% !important;
	}

	.registers_flex_0 {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
	}

	.registers_fd0_0_c2 {
		width: 32rpx;
		height: 32rpx;
	}

	.registers_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.registers_fd1_0_c0 {
		background: transparent;
		width: 180rpx;
		height: 180rpx;
		border-radius: 16rpx;
		background-size: 100% auto !important;
	}

	.registers_fd1_0 {
		padding: 50rpx 0rpx 80rpx 0rpx;
	}

	.registers_flex_2 {
		padding: 0rpx 56rpx 0rpx 56rpx;
	}

	.registers_fd2_5_c1 {
		font-size: 28rpx;
		font-weight: 700;
		color: #3481e9;
	}

	.registers_fd2_5_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(191, 191, 191, 1);
	}

	.registers_fd2_5 {
		line-height: 40rpx;
		margin-top: 15rpx
	}

	.registers_fd2_4_c0 {
		background: #6A0002;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		height: 88rpx;
		line-height: 88rpx;
		font-weight: 500;
	}

	.registers_fd2_4 {
		margin: 85rpx 0rpx 0rpx 0rpx;
	}

	.registers_fd2_2_c1_icon2 {
		text-align: center;
		font-size: 44rpx;
	}

	.MyInformation_picker5_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}

	.MyInformation_picker5_0_c2 {
		color: #4781f5;
	}

	.registers_fd2_2_c1_icon1 {
		text-align: center;
		font-size: 44rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	::v-deep .registers_fd2_2_c1 {
		font-size: 32rpx;
		color: #f5f5f5;
		font-weight: 400;
		width: 550rpx;
	}

	.registers_fd2_1_c2 {
		font-size: 28rpx;
		font-weight: 500;
		color: #3481e9;
	}

	.registers_fd2_1_c1 {
		line-height: 45rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #f5f5f5;
	}

	.registers_fd2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #f5f5f5;
	}

	.registers_fd2_0_c0 {
		width: 34rpx;
		height: 34rpx;
		margin: 0rpx 28rpx 0rpx 0rpx;
	}

	.registers_fd2_0 {
		border-bottom: 1px solid #eee;
		padding: 40rpx 0rpx 40rpx 0rpx;
	}

	.registers_flex_3 {
		width: 750rpx;
		height: 90rpx;
		overflow: hidden;
		z-index: 10;
		// margin-top: 30rpx;
		// position: absolute;
		// bottom: calc(0rpx + var(--window-bottom));
	}

	.registers_fd3_3 {
		line-height: 32rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	.registers_fd3_2 {
		line-height: 32rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #3481e9;
	}

	.registers_fd3_1 {
		line-height: 32rpx;
		font-size: 22rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
		margin: 0rpx 0rpx 0rpx 12rpx;
	}

	.registers_noCheckfd3_0_c1_c0 {
		width: 36rpx;
		height: 36rpx;
	}

	.registers_checkfd3_0_c0_c0 {
		width: 36rpx;
		height: 36rpx;
	}

	.registers_checkfd3_0_c0 {
		width: 36rpx;
		height: 36rpx;
	}
</style>